home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-15 | 21.7 KB | 824 lines | [TEXT/CWIE] |
- Program SimpleViewer;
- {--------------------------------------------------------------------------------------------
- // simple viewer application
- // DEVELOPER SUPPORT May 95
- //
- // This is a simple viewer application, that illustrates a minimal, but
- // functionally complete viewer application.
- //
- // Nick Thompson, Developer Support, Apple Computer (DEVSUPPORT),
- // ©1995, Apple Computer Inc., All Rights Reserved
- }
-
- Uses
- Windows, Fonts, Dialogs, Processes, ToolUtils, Devices, StandardFile, AppleEvents,
- GestaltEqu, SegLoad, Scrap, DiskInit,
- QDOffscreen, QD3DViewer, QD3D, QD3DMath, QD3DDrawContext,
- QD3DShader, QD3DTransform, QD3DGroup, QD3DStyle, QD3DView;
-
- Const
- kWindowWidth = 220;
- kWindowHeight = 150;
-
- mApple = 128;
- mFile = 129;
- mEdit = 130;
-
- iAbout = 1;
-
- iNew = 1;
- iOpen = 2;
- iUnused1 = 3;
- iClose = 4;
- iSave = 5;
- iSaveAs = 6;
- iRevert = 7;
- iUnused2 = 8;
- iQuit = 9;
-
- iUndo = 1;
- iUnused3 = 2;
- iCut = 3;
- iCopy = 4;
- iPaste = 5;
- iClear = 6;
-
- Var
- gQuitFlag: boolean;
- gStaggerPos: Point;
- gSelfAddress: AEAddressDesc;
- gSelfPSN: ProcessSerialNumber;
- kRGBBlack: RGBColor;
- kRGBWhite: RGBColor;
-
- Const
- kmyAboutDialogID = 128;
- kmyFatalDialogID = 129;
- kQD3DAlertID = 27309;
-
- Type
- ViewerData = record
- theViewer: TQ3ViewerObject;
- theFile: FSSPec;
- isFileValid: boolean;
- end;
- ViewerDataPtr = ^ViewerData;
- ViewerDataHandle = ^ViewerDataPtr;
-
- Function HiWrd (alongint: longint): Integer;
-
- begin
- HiWrd := Point(alongint).v;
- end;
-
- Function LoWrd (alongint: longint): Integer;
-
- begin
- LoWrd := Point(alongint).h;
- end;
-
- Function SupportsQuickDraw3D: boolean;
-
- Var
- err: OSErr;
- response: longint;
-
- begin
- err := Gestalt(gestaltQD3D,response);
- if err = NoErr then
- SupportsQuickDraw3D := (response > 0) and
- (BSL(response,gestaltQD3DAvailable) > 0)
- else
- SupportsQuickDraw3D := false;
- end;
-
- Function SupportsQuickDraw3DViewer: boolean;
-
- Var
- err: OSErr;
- response: longint;
-
- begin
- err := Gestalt(gestaltQD3DViewer,response);
- if err = NoErr then
- SupportsQuickDraw3DViewer := (response > 0) and
- (BSL(response,gestaltQD3DViewerAvailable) > 0)
- else
- SupportsQuickDraw3DViewer := false;
- end;
-
- Procedure FailIfErr(something: OSErr);
-
- Var
- theProc: ModalFilterUPP;
- theDialog: DialogPtr;
- itemHit: integer;
- theError: Str255;
-
- begin
- if something <> noErr then
- begin
- NumToString(something,theError);
- theDialog := GetNewDialog(kMyFatalDialogID, nil, WindowPtr(-1));
- { these two lil' snappers are system 7 only }
- { so if you use them, check before!! }
- { in this app we will only run on Power }
- { Macintosh, so we don't check }
- if GetStdFilterProc(theProc) = noErr then;
- if SetDialogDefaultItem(theDialog, ok) = noErr then;
- ParamText( theError, '', '', '') ;
- { put the dialog up and loop til}
- { the user hits the OK button }
- repeat
- ModalDialog(theProc,itemHit);
- until itemHit = ok;
- DisposeDialog(theDialog);
- ExitToShell;
- end;
- end;
-
- Procedure HandleActivateWindow(theWindow: WindowPtr; activate: integer);
-
- begin
- if theWindow <> NIL then
- begin
- if activate <> 0 then
- begin
- if LoadScrap = noErr then;
- end
- else
- if UnloadScrap = noErr then;
- end;
- end;
-
- Procedure HandleAboutApp;
-
- Var
- theProc: ModalFilterUPP;
- theDialog: DialogPtr;
- itemHit: integer;
-
- begin
- theDialog := GetNewDialog(kMyAboutDialogID, nil, WindowPtr(-1));
- { these two lil' snappers are system 7 only }
- { so if you use them, check before!! }
- { in this app we will only run on Power }
- { Macintosh, so we don't check }
- if GetStdFilterProc(theProc) = noErr then;
- if SetDialogDefaultItem(theDialog, ok) = noErr then;
- { put the dialog up and loop til }
- { the user hits the OK button }
- repeat
- ModalDialog(theProc,itemHit);
- until itemHit = ok;
- DisposeDialog(theDialog);
- end;
-
- Procedure MyAdjustMenus;
-
- Var
- theWindow: WindowPtr;
- myData: ViewerDataHandle;
- theMenu: MenuHandle;
-
- begin
- theWindow := FrontWindow;
- if theWindow <> nil then
- begin
- theMenu := GetMenuHandle(mFile);
- EnableItem(theMenu,iClose);
- EnableItem(theMenu,iSaveAs);
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- if myData^^.isFileValid then
- begin
- EnableItem(theMenu,iSave);
- EnableItem(theMenu,iRevert);
- end
- else
- begin
- DisableItem(theMenu,iSave);
- DisableItem(theMenu,iRevert);
- end;
- EnableItem(GetMenuHandle(mEdit),0);
- end
- else
- begin
- theMenu := GetMenuHandle(mFile);
- DisableItem(theMenu, iClose);
- DisableItem(theMenu, iRevert);
- DisableItem(theMenu, iSave);
- DisableItem(theMenu, iSaveAs);
- DisableItem(GetMenuHandle(mEdit), 0);
- end;
- { we dont support undo }
- DisableItem(GetMenuHandle(mEdit), iUndo);
- DrawMenuBar;
- end;
-
- Function MyDisposeViewerWindow(theWindow: WindowPtr): OSErr;
-
- Var
- theViewer: TQ3ViewerObject;
- myData: ViewerDataHandle;
-
- begin
- if theWindow = nil then
- begin
- MyDisposeViewerWindow := paramErr;
- exit(MyDisposeViewerWindow);
- end;
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theViewer := myData^^.theViewer;
- DisposeHandle(Handle(myData));
- DisposeWindow(theWindow);
- MyAdjustMenus;
- MyDisposeViewerWindow := Q3ViewerDispose(theViewer);
- end;
-
- Function MyCreateViewerWindow: CGrafPtr;
-
- Var
- theRect: Rect;
- savedPort: GrafPtr;
- myViewerObj: TQ3ViewerObject;
- theWindow: WindowPtr;
- myData: ViewerDataHandle;
-
- begin
- myData := ViewerDataHandle(NewHandle(sizeof(ViewerData)));
- GetPort(savedPort);
- { set the new rect up with a stagger for multiple windows }
- SetRect(theRect, gStaggerPos.h, gStaggerPos.v, gStaggerPos.h + kWindowWidth,
- gStaggerPos.v + kWindowHeight);
- gStaggerPos.h := gStaggerPos.h + 16;
- gStaggerPos.v := gStaggerPos.v + 16; { this is not "real staggering code, it dont wrap }
- theWindow := NewCWindow(nil, theRect, 'Untitled', false, documentProc, WindowPtr(-1),
- true, 0);
- SetPort(GrafPtr(theWindow));
- { set up the viewer object here }
- myViewerObj := Q3ViewerNew(CGrafPtr(theWindow), theWindow^.portRect, kQ3ViewerDefault);
- { stuff the reference to the viewer in the RefCon field of the Window }
- myData^^.theViewer := myViewerObj;
- myData^^.isFileValid := false;
- SetWRefCon(theWindow, longint(myData));
- { make sure it is visible }
- ShowWindow(theWindow);
- { invalidate the content region of the window - }
- { we dont do any drawing to it here. }
- InvalRect (theRect);
- SetPort(savedPort);
- MyCreateViewerWindow := CGrafPtr(theWindow);
- end;
-
- Function HandleOpenDoc(theFile: FSSpec): OSErr;
-
- Var
- err: OSErr;
- theRef: integer;
- myData: ViewerDataHandle;
- theViewer: TQ3ViewerObject;
- theWindow: WindowPtr;
-
- begin
- theWindow := WindowPtr(MyCreateViewerWindow);
- { open the file }
- err := FSpOpenDF(theFile,fsRdPerm,theRef);
- if err = noErr then
- begin
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theViewer := myData^^.theViewer;
- myData^^.theFile := theFile;
- myData^^.isFileValid := true ;
- if Q3ViewerUseFile(theViewer, theRef) = noErr then ;
- err := FSClose(theRef) ;
- end;
- { set the window title }
- SetWTitle(theWindow, theFile.name);
- MyAdjustMenus;
- HandleOpenDoc := err;
- end;
-
- Function SupportsAEVT: Boolean;
-
- Var
- err: OSErr;
- response: longint;
-
- begin
- err := Gestalt(gestaltAppleEventsAttr,response);
- if err = noErr then
- SupportsAEVT := (response > 0) and
- (BSL(response,gestaltAppleEventsPresent) > 0)
- else
- SupportsAEVT := false;
- end;
-
- Function MyAEHandleOAPP(var theAppleEvent, reply: AppleEvent; refCon: longint): OSErr;
-
- { we don't actually do anything on open - you could, }
- { for example you might want to open a blank untitled }
- { window }
-
- Var
- err: OSErr;
-
- begin
- err := noErr ;
- MyAEHandleOAPP := err;
- end;
-
- Function MyAEHandleODOC(var theAppleEvent, reply: AppleEvent; refCon: longint): OSErr;
-
- Var
- myFSS: FSSpec;
- docList: AEDescList;
- err,ignoreErr: OSErr;
- index: longint;
- itemsInList: longint;
- actualSize: Size;
- keywd: AEKeyword;
- returnedType: DescType;
- fndrInfo: FInfo;
-
- begin
- err := AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,docList);
- if err = noErr then
- begin
- { see how many descriptor items are in the list }
- { this is the number of documents we want to open }
- err := AECountItems(docList,itemsInList);
- { now get each descriptor record from the list }
- { coerce the returned data to an FSSpec record, and }
- { open the asoociated file }
- for index := 1 to itemsInList do
- begin
- err := AEGetNthPtr(docList, index, typeFSS, keywd, returnedType,
- @myFSS, sizeof(myFSS), actualSize);
- if err <> NoErr then
- leave;
- { we now have a valid FSSpec to reference the file, we need to know }
- { what type the file is to determine which file open function to call }
- { we can determine this from the finder info for the file }
- err := FSpGetFInfo(myFSS, fndrInfo);
- if err <> NoErr then
- leave;
- { if we got that ok, then we check on the file }
- { type (we dont care about the creator type) }
- if (fndrInfo.fdType = 'TEXT') or (fndrInfo.fdType = '3DMF') then
- err := HandleOpenDoc(myFSS);
- if err <> NoErr then
- leave;
- end;
- ignoreErr := AEDisposeDesc(docList);
- end;
- MyAEHandleODOC := err;
- end;
-
- Function MyAEHandlePDOC(var theAppleEvent, reply: AppleEvent; refCon: longint): OSErr;
-
- Var
- myFSS: FSSpec;
- docList: AEDescList;
- err: OSErr;
- index: longint;
- itemsInList: longint;
- actualSize: Size;
- keywd: AEKeyword;
- returnedType: DescType;
-
- begin
- err := AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,docList);
- if err <> NoErr then
- begin
- MyAEHandlePDOC := err;
- exit(MyAEHandlePDOC);
- end;
- { see how many descriptor items are in the list }
- { this is the number of documents we want to open }
- err := AECountItems(docList,itemsInList);
- { now get each descriptor record from the list }
- { coerce the returned data to an FSSpec record, and }
- { open the asoociated file }
- for index := 1 to itemsInList do
- begin
- err := AEGetNthPtr(docList, index, typeFSS, keywd, returnedType,
- @myFSS, sizeof(myFSS), actualSize);
- if err <> NoErr then
- leave;
- { err := HandlePrintDoc( &myFSS ); }
- err := errAEEventNotHandled; { we don't do this yet... }
- err := AEDisposeDesc(docList);
- end;
- MyAEHandlePDOC := err;
- end;
-
- Function MyAEHandleQUIT(var theAppleEvent, reply: AppleEvent; refCon: longint): OSErr;
-
- Var
- err: OSErr;
- theWindow: WindowPtr;
- quitting: Boolean;
-
- begin
- err := noErr;
- quitting := true;
- { attempt to close all documents }
- theWindow := FrontWindow;
- while (theWindow <> NIL) and quitting do
- begin
- quitting := MyDisposeViewerWindow(theWindow) = noErr;
- if quitting then
- theWindow := FrontWindow;
- end;
- { if we closed everything up successfully, we can return noErr, otherwise }
- { indicate to sender of the 'quit' aevt that we canceled }
- if quitting then
- begin
- gQuitFlag := true; { user didn't cancel }
- if AEDisposeDesc(gSelfAddress) = noErr then; { Dispose of my self-addressed descriptor }
- end
- else
- err := userCanceledErr;
- MyAEHandleQUIT := err;
- end;
-
- Procedure RegisterMyEvents;
-
- Var
- err: OSErr;
-
- begin
- if not SupportsAEVT then
- exit(RegisterMyEvents);
- err := AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,
- NewAEEventHandlerProc(MyAEHandleOAPP),0,false);
- if err <> noErr then
- exit(RegisterMyEvents);
- err := AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
- NewAEEventHandlerProc(MyAEHandleODOC),0,false);
- if err <> noErr then
- exit(RegisterMyEvents);
- err := AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
- NewAEEventHandlerProc(MyAEHandlePDOC),0,false);
- if err <> noErr then
- exit(RegisterMyEvents);
- err := AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
- NewAEEventHandlerProc(MyAEHandleQUIT),0,false);
- end;
-
- Procedure MySendQuitApp;
-
- Var
- myAppleEvent, reply: AppleEvent;
-
- begin
- { Create the Apple Event. }
- FailIfErr(AECreateAppleEvent(kCoreEventClass, kAEQuitApplication, gSelfAddress,
- kAutoGenerateReturnID, kAnyTransactionID, myAppleEvent));
- { Send the Apple Event. }
- FailIfErr(AESend(myAppleEvent, reply, kAENoReply+kAENeverInteract,
- kAENormalPriority, kAEDefaultTimeout, nil, nil));
- if AEDisposeDesc(myAppleEvent) = noErr then; { Dispose of the Apple Event. }
- end; { of MySendQuitApp }
-
- Procedure MySendOpenDoc(myFSSpec: FSSpec);
-
- Var
- myAppleEvent: AppleEvent;
- defReply: AppleEvent;
- docList: AEDescList;
- myErr: OSErr;
- ignoreErr: OSErr;
-
- begin
- myAppleEvent.dataHandle := nil;
- docList.dataHandle := nil;
- defReply.dataHandle := nil;
- { Create empty list and add one file spec }
- FailIfErr(AECreateList(nil,0,false, docList));
- FailIfErr(AEPutPtr(docList,1,typeFSS,@myFSSpec,sizeof(FSSpec)));
- FailIfErr(AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments,
- gSelfAddress, kAutoGenerateReturnID, kAnyTransactionID, myAppleEvent));
- { Put Params into our event and send it }
- FailIfErr(AEPutParamDesc(myAppleEvent, keyDirectObject, docList));
- FailIfErr(AESend(myAppleEvent, defReply, kAENoReply+kAENeverInteract,
- kAENormalPriority, kAEDefaultTimeout, nil, nil));
- if myAppleEvent.dataHandle <> nil then
- ignoreErr := AEDisposeDesc(myAppleEvent);
- if docList.dataHandle <> nil then
- ignoreErr := AEDisposeDesc(docList);
- end; { of MySendOpenDoc }
-
- Procedure HandleMenuCommand(menuResult: longint);
-
- Var
- menuID: integer;
- menuItem: integer;
- daName: Str255;
- numTypes: integer;
- myTypes: array[1..2] of OSType;
- err: OSErr;
- theRef: integer;
- myData: ViewerDataHandle;
- theViewer: TQ3ViewerObject;
- theWindow: WindowPtr;
- savedPort: GrafPtr;
- theFile: FSSpec;
- theSFReply: StandardFileReply;
-
- begin
- myTypes[1] := '3DMF';
- myTypes[2] := 'TEXT';
- numTypes := 2;
- menuID := HiWrd(menuResult);
- menuItem := LoWrd(menuResult);
- Case menuID of
- mApple: case menuItem of
- iAbout: HandleAboutApp ;
- otherwise begin
- GetMenuItemText(GetMenuHandle(mApple), menuItem, daName);
- if OpenDeskAcc(daName) = noErr then;
- end;
- {case} end;
- mFile: case menuItem of
- iNew: theWindow := WindowPtr(MyCreateViewerWindow);
- iOpen: begin
- { Get the file name to open }
- StandardGetFile( nil, numTypes, @myTypes, theSFReply);
- { did the user cancel, if not open the file? }
- if theSFReply.sfGood then
- MySendOpenDoc(theSFReply.sfFile);
- end;
- iRevert: begin
- { we know this cant be called as longint as there }
- { is an app window open (MyAdjustMenus) so get the refcon }
- { from the front window and get the FSSpec from that }
- theWindow := FrontWindow;
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theFile := myData^^.theFile;
- { open the file and read it back into the viewer }
- err := FSpOpenDF(theFile,fsRdPerm,theRef);
- if err = noErr then
- begin
- theViewer := myData^^.theViewer;
- if Q3ViewerUseFile(theViewer, theRef) = noErr then;
- err := FSClose(theRef) ;
- end;
- GetPort(savedPort);
- SetPort(GrafPtr(theWindow));
- InvalRect(theWindow^.portRect);
- SetPort(savedPort);
- end;
- iSave: begin
- { we know this cant be called as longint as there }
- { is an app window open (MyAdjustMenus) so get the refcon }
- { from the front window and get the FSSpec from that }
- theWindow := FrontWindow;
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theFile := myData^^.theFile;
- theViewer := myData^^.theViewer ;
- { assumes the original file still exists }
- err := FSpOpenDF(theFile,fsWrPerm,theRef);
- if err = noErr then
- begin
- if Q3ViewerWriteFile(theViewer, theRef) = noErr then;
- err := FSClose(theRef);
- end;
- end;
- iSaveAs: begin
- { we know this cant be called as longint as there }
- { is an app window open (MyAdjustMenus) so get the refcon }
- { from the front window and get the FSSpec from that }
- theWindow := FrontWindow;
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theViewer := myData^^.theViewer;
- StandardPutFile('Save model as:', 'Untitled', theSFReply);
- if theSFReply.sfGood then
- begin
- err := FSpOpenDF(theSFReply.sfFile,fsWrPerm,theRef);
- if err <> noErr then
- begin
- err := FSpCreate(theSFReply.sfFile, '????', '3DMF',
- theSFReply.sfScript);
- if err = noErr then
- err := FSpOpenDF(theSFReply.sfFile, fsCurPerm, theRef);
- end;
- if err = noErr then
- begin
- if Q3ViewerWriteFile(theViewer, theRef) = noErr then;
- err := FSClose(theRef);
- end;
- { set up our record of the file location, }
- { update the structure }
- theWindow := FrontWindow ;
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theViewer := myData^^.theViewer ;
- myData^^.theFile := theSFReply.sfFile;
- myData^^.isFileValid := true;
- { reset the window title }
- SetWTitle(theWindow, theSFReply.sfFile.name);
- end;
- end;
- iClose: if MyDisposeViewerWindow(FrontWindow) = noErr then;
- iQuit: MySendQuitApp;
- {case} end;
- mEdit: begin
- theWindow := FrontWindow;
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theViewer := myData^^.theViewer;
- case menuItem of
- iCut: if Q3ViewerCut(theViewer) = noErr then;
- iCopy: if Q3ViewerCopy(theViewer) = noErr then;
- iPaste: if Q3ViewerPaste(theViewer) = noErr then;
- iClear: if Q3ViewerClear(theViewer) = noErr then;
- otherwise;
- {case} end;
- end;
- {Case} end;
- HiliteMenu(0); { Unhighlight whatever MenuSelect or MenuKey hilited }
- end;
-
- Procedure HandleKeyPress(event: EventRecord);
-
- Var
- key: char;
-
- begin
- key := chr(BAnd(event.message,charCodeMask));
- { just check to see if we want to quit... }
- if BAnd(event.modifiers,cmdKey) > 0 then { Command key down? }
- HandleMenuCommand(MenuKey(key));
- end;
-
- Function HandleEvent(theEvent: EventRecord): boolean;
-
- Var
- thePart: integer;
- theWindow: WindowPtr;
- screenRect: Rect;
- oldPort: GrafPtr;
- aPoint: Point;
- theViewer: TQ3ViewerObject;
- myData: ViewerDataHandle;
-
- begin
- setPt(aPoint,100,100);
- case theEvent.what of
- mouseDown:
- begin
- thePart := FindWindow(theEvent.where, theWindow);
- case thePart of
- inMenuBar: begin
- MyAdjustMenus;
- HandleMenuCommand(MenuSelect(theEvent.where));
- end;
- inDrag: begin
- screenRect := GetGrayRgn^^.rgnBBox;
- DragWindow(theWindow,theEvent.where,screenRect);
- end;
- inContent: if theWindow <> FrontWindow then
- SelectWindow(theWindow);
- inGoAway: if TrackGoAway(theWindow, theEvent.where) then
- if MyDisposeViewerWindow(theWindow) = noErr then;
- otherwise;
- {case} end;
- end;
- updateEvt:
- begin
- theWindow := WindowPtr(theEvent.message);
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theViewer := myData^^.theViewer;
- GetPort(oldPort);
- SetPort(theWindow);
- BeginUpdate(theWindow);
- if Q3ViewerDraw(theViewer) = noErr then;
- EndUpdate(theWindow);
- SetPort(oldPort);
- end;
- keyDown, autoKey:
- HandleKeyPress(theEvent);
- diskEvt:
- if HiWrd(theEvent.message) <> noErr then
- if DIBadMount(aPoint, theEvent.message) = noErr then;
- osEvt: { does nothing }
- ;
- activateEvt:
- begin
- theWindow := WindowPtr(theEvent.message);
- if theWindow <> nil then
- HandleActivateWindow(theWindow,BAnd(theEvent.modifiers,activeFlag));
- end;
- kHighLevelEvent: { Let the Apple Event Manager handle high level event. }
- if AEProcessAppleEvent(theEvent) = noErr then;
- {case} end;
- HandleEvent := true;
- end;
-
- Procedure MainEventLoop;
-
- Var
- event: EventRecord;
- theWindow: WindowPtr;
- wasViewerEvent: Boolean;
- savedPort: GrafPtr;
- localPt: Point;
- theViewer: TQ3ViewerObject;
- myData: ViewerDataHandle;
-
- begin
- MyAdjustMenus;
- while not gQuitFlag do
- begin
- if WaitNextEvent(everyEvent,event,0,nil) then
- begin
- theWindow := FrontWindow;
- if theWindow <> nil then
- begin
- myData := ViewerDataHandle(GetWRefCon(theWindow));
- theViewer := myData^^.theViewer;
- end;
- if theViewer <> nil then
- begin
- GetPort(savedPort);
- SetPort(GrafPtr(theWindow));
- GetMouse(localPt);
- if not Q3ViewerAdjustCursor(theViewer,localPt) then
- InitCursor;
- wasViewerEvent := Q3ViewerEvent(theViewer,event);
- SetPort(savedPort);
- end
- else
- wasViewerEvent := false;
- if not wasViewerEvent then
- if HandleEvent(event) then;
- end;
- end;
- end;
-
- Procedure Initialize;
-
- Var
- menuBar: Handle;
-
- begin
- InitGraf(@qd.thePort);
- InitFonts;
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(nil);
- InitCursor;
- gQuitFlag := false;
- SetPt(gStaggerPos,50,50);
- with kRGBBlack do
- begin
- red := 0; green := 0; blue := 0;
- end;
- with kRGBWhite do
- begin
- red := $FFFF; green := $FFFF; blue := $FFFF;
- end;
- menuBar := GetNewMBar(128); { Read menus into menu bar, MBAR res id is 128 }
- if menuBar = nil then
- ExitToShell; { if we dont have it then quit - your app }
- SetMenuBar(menuBar); { Install menus }
- DisposeHandle(menuBar);
- AppendResMenu(GetMenuHandle(mApple), 'DRVR'); { Add DA names to Apple menu, ID 128 }
- MyAdjustMenus;
- DrawMenuBar;
- end;
-
- Var
- theString: Str255;
-
- Begin
- MoreMasters;
- MoreMasters;
- MoreMasters;
- MaxApplZone; { Maximize the heap - the viewer requires at least 32k }
- Initialize;
- {
- WE DON'T CHECK FOR 68K machine.
- Instead I use the NotPPC.rsrc resource file. This is a file with a 68k CODE 0
- and CODE 1 resource that puts up a dialog that says "this app only runs on a power
- macintosh computer.
- }
- if SupportsAEVT and SupportsQuickDraw3D and SupportsQuickDraw3DViewer then
- begin
- { AppleEvent stuff: }
- { Set up the self-addressed descriptor record. }
- gSelfPSN.highLongOfPSN := 0;
- gSelfPSN.lowLongOfPSN := kCurrentProcess; { Use this instead of GetCurrentProcess }
- FailIfErr(AECreateDesc(typeProcessSerialNumber,@gSelfPSN,sizeof(ProcessSerialNumber),
- gSelfAddress));
- RegisterMyEvents; { register the appleevents for this app }
- MainEventLoop; { Handle events 'til we die }
- end
- else
- begin
- GetIndString(theString,kQD3DAlertID,3);
- ParamText(theString, '', '', '');
- if Alert(kQD3DAlertID, nil) = noErr then;
- end
- end.
-